package tgc.edu.yzy.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="yzy_teacher")
public class Teacher {
	private Integer id;
	private String tcname;//任课老师姓名
	private	String course;//课程
	private String tcuser;//老师登陆账号 （工号）
	private String tcpassword;//登陆密码
	private List<Grade> grade=new ArrayList<>();
	private List<Student> student=new ArrayList<>();
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=20)
	public String getTcname() {
		return tcname;
	}
	public void setTcname(String tcname) {
		this.tcname = tcname;
	}
	@Column(length=20)
	public String getCourse() {
		return course;
	}
	public void setCourse(String course) {
		this.course = course;
	}
	@Column(length=20,nullable=false,unique=true)
	public String getTcuser() {
		return tcuser;
	}
	public void setTcuser(String tcuser) {
		this.tcuser = tcuser;
	}
	@Column(length=20)
	public String getTcpassword() {
		return tcpassword;
	}
	public void setTcpassword(String tcpassword) {
		this.tcpassword = tcpassword;
	}
	@OneToMany(cascade=CascadeType.ALL,mappedBy="teacher")
	public List<Grade> getGrade() {
		return grade;
	}
	public void setGrade(List<Grade> grade) {
		this.grade = grade;
	}
	@Transient
	public List<Student> getStudent(){
		List<Student> student=new ArrayList<>();
		for(Grade grades:getGrade()) {
			student.add(grades.getStudent());
		}
		return student;
	}
	
	public Teacher(Integer id, String tcname, String course, String tcuser, String tcpassword, List<Grade> grade) {
		super();
		this.id = id;
		this.tcname = tcname;
		this.course = course;
		this.tcuser = tcuser;
		this.tcpassword = tcpassword;
		this.grade = grade;
	}
	public Teacher() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Teacher(Integer id) {
		super();
		this.id = id;
	}
	
	
}
